<?php 

/*
 *------------------------------------------------------------------------------
 * Project Name  : e-Synergy Library System
 *         Code  : ESN-LBS
 *
 * Created By    : Junlapong
 *         Date  : 2010/01/20
 *
 * $Id$
 *------------------------------------------------------------------------------
 *    copyright: e-Synergy Co., Ltd.
 *==============================================================================
 */

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @author Junlapong
 *
 */
class MY_Session extends CI_Session
{
	// TODO: var $sess_delete_after_browser_close	= TRUE;
	
	/**
	 * @param $params
	 * @return unknown_type
	 */
	function MY_Session($params = array())
	{
		parent::CI_Session($params);		
		log_message('debug', "MY_Session Class Initialized");
	}
	
	/**
	 * set session data with specific key
	 * 
	 * @param $key
	 * @param $value
	 */
	function set($key, $value)
	{
		$this->set_userdata($key, $value);
	}
	
	/**
	 * get session data with specific key
	 * 
	 * @param $key
	 * @return session value
	 */
	function get($key)
	{
		return $this->userdata($key);
	}
	
	/**
	 * remove session data with specific key
	 * 
	 * @param $key
	 */
	function remove($key)
	{
		$this->unset_userdata($key);
	}
	
	/**
	 * 
	 * destroy session data
	 */
	function invalidate()
	{
		$this->sess_destroy();
	} 
	
	/**
	 * 
	 * @return session id
	 */
	function getId()
	{
		return $this->get('session_id');
	}
	
	/**
	 * 
	 * @return session created time
	 */
	function getCreatedTime() 
	{
		return NULL;
	}	
	
	/**
	 * 
	 * @return session last accessed time
	 */
	function getLastAccessedTime()
	{
		return $this->get('last_activity');
	} 
	
	
	/* @override CI_Session#_serialize
	 * 
	 * @see system/libraries/CI_Session#_serialize($data)
	 */
	function _serialize($data)
	{	
		return base64_encode(serialize($data));
	}
	
	/* @override CI_Session#_unserialize
	 * 
	 * @see system/libraries/CI_Session#_unserialize($data)
	 */
	function _unserialize($data)
	{
		// TODO include all entity file auto
		include_once(APPPATH . 'models/entities/user_entity.php');
		
		return unserialize(base64_decode($data));
	}

}

// END MY_Session class

/* End of file MY_Session */
/* Location: application/libraries/MY_Session.php */